<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>新增跟踪记录弹出页面</title>

    <link rel="stylesheet" href="../layui/css/layui.css">
    <link rel="stylesheet" href="../styles/layui-alter.css">
    <link rel="stylesheet" href="../styles/center.css">

</head>
<body>
<div class="m-center-10">
    <form method="post" action="/static" class="layui-form">
        <div class="layui-form-item">
            <label class="layui-form-label">托运单号：</label>
            <div class="layui-input-inline">
                <input type="text" name="trackConsignNum" class="layui-input input-m" lay-verify="required">
            </div>
            <label class="layui-form-label">更新日期：</label>
            <div class="layui-input-inline">
                <input type="datetime-local" name="trackDate" id="track-date" class="layui-input" lay-verify="required">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">跟踪类型：</label>
            <div class="layui-input-inline">
                <select name="trackType" lay-verify="required">
                    <option value="">请选择跟踪类型</option>
                    <option value="1">收件</option>
                    <option value="2">装车</option>
                    <option value="3">运输</option>
                    <option value="4">转运</option>
                    <option value="5">派送</option>
                    <option value="6">签收</option>
                </select>
            </div>
            <label class="layui-form-label">记录站点：</label>
            <div class="layui-input-inline">
                <select name="trackRecordSubst" lay-verify="required">
                    <option value="">请选择站点</option>
                </select>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">跟踪状态：</label>
            <div class="layui-input-block">
                <input type="text"  name="trackStatus" class="layui-input" lay-verify="required">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button type="button" style="margin:10% 30% 0 30%;" class="layui-btn pool-blue btn-r" lay-submit lay-filter="addTrack">新增跟踪记录</button>
            </div>
        </div>
    </form>
</div>

<script src="../layui/layui.js"></script>
<script>
    layui.use(['form', 'laydate', 'jquery'],function () {
        var form = layui.form;
        var laydate = layui.laydate;
        var $ = layui.jquery;

        //加载跟踪记录分站
        loadSubstList("trackRecordSubst");
        //新增跟踪记录监听提交
        form.on('submit(addTrack)', function(data){
            console.log(data.field);

            $.ajax({
                url:"/addTrack",
                type: "POST",
                dataType:'json',
                contentType: "application/json;charset=UTF-8",
                data: JSON.stringify(data.field),
                success:function(msg){
                    console.log(msg);
                    layer.msg(msg['msg'],
                        {
                            icon: 6,
                            time: 1400,
                            end:function () {
                                if (msg['result'] == "success") {
                                    var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                                    parent.layer.close(index); //再执行关闭
                                } else {

                                }
                            }
                        }
                    );

                }
            });
            return false;
        });
        form.render();


        /**
         * 加载--分站--下拉框列表的方法
         * @param selectName 下拉框name,可以是str类型和arr类型
         */
        function loadSubstList(selectName) {
            $.ajax({
                type: "POST",
                url: "/getSubstationListFS",
                success: function (data) {
                    for (var i = 0; i < data.length; i++) {
                        var li = "<option value='" + data[i]['substId'] + "'>" + data[i]['substName'] + "</option>"

                        if (typeof selectName == "string") {
                            $("select[name='" + selectName + "']").append(li);
                        } else if (typeof selectName != "undefined") {
                            for (var j = 0; j < selectName.length; j++) {
                                $("select[name='" + selectName[j] + "']").append(li);
                            }
                        }
                    }
                    form.render("select");
                }
            });
        }
    })
</script>
</body>
</html>